package com.decent.ejfadmin.common.bean;


import com.decent.ejfadmin.common.enums.SupWebErrorCode;
import com.decent.ejfadmin.common.exception.ErrorCodeException;
import lombok.Data;

import java.math.BigDecimal;

/***
 * 供货明细
 * @author hejunlei
 */
@Data
public class SupplyConsumption {
    /**
     * 支付宝提现
     */
    public static final String ALIPAY = "alipay";
    /**
     * 银行卡提现
     */
    public static final String BANK = "bank";
    /**
     * 供卡提现
     */
    public static final int SUPPLYCARD_TYPE = 0;
    /**
     * 佣金提现
     */
    public static final int RECOMMEND_TYPE = 1;
    /**
     * 结算类型
     */
    public static final int SETTLE_TYPE = 1;
    /**
     * 提现类型（审核中）
     */
    public static final int WITHDRAW_TYPE = 2;
    /**
     * 提现失败退款类型
     */
    public static final int WITHDRAW_RETURN_TYPE = 3;
    /**
     * 提现成功
     */
    public static final int WITHDRAW_SUCCESS = 4;
    /**
     * 提现失败
     */
    public static final int WITHDRAW_FAIL = 5;
    /**
     * 返点
     */
    public static final int REBATE = 6;
    /**
     * 补结算
     */
    public static final int ADDED = 7;
    /**
     * 补差额
     */
    private static final int FIXED = 8;
    /**
     * 手续费
     */
    public static final int SERVICE_TYPE = 9;
    /**
     * 提现手续费失败
     */
    public static final int SERVICE_TYPE_FAIL = 10;
    /**
     * 补手续费
     */
    public static final int MAKE_UP_SERVICE_TYPE = 11;
    /**
     * 补扣款
     */
    public static final int MAKE_UP_WITHHOLD = 13;
    /**
     * 手动退款
     */
    public static final int MANUAL_REFUND = 12;
    /**
     * 佣金提现
     */
    public static final int CONSUMPTION = 1;
    /**
     * 提现
     */
    public static final int WITHDRAW = 0;

    /**
     * 自增id
     */
    private Long id;
    /**
     * 会员id
     */
    private Long userId;
    /**
     * 时间
     */
    private Long startTime;
    /**
     * 消费类型，1结算，2提现申请，3提现失败退款,4提现成功,5提现失败,6返佣,7补结算,8补差额
     */
    private Integer consumeType;
    /**
     * 订单号
     */
    private String orderId;
    /**
     * 渠道
     */
    private String channel;
    /**
     * 消费金额
     */
    private BigDecimal money;
    /**
     * 当前余额
     */
    private BigDecimal balance;
    /**
     * 0 其他/1 返佣(提现)
     */
    private Integer type;

    public SupplyConsumption() {
    }

    public SupplyConsumption(Long userId, Integer consumeType, String orderId, String channel, BigDecimal money, Integer type) {
        this.userId = userId;
        this.consumeType = consumeType;
        this.orderId = orderId;
        this.channel = channel;
        this.money = money;
        this.type = type;
    }

    @Override
    public String toString() {
        final StringBuffer sb = new StringBuffer(100).append("SupplyConsumption{");
        sb.append("id=").append(id);
        sb.append(", userId=").append(userId);
        sb.append(", startTime=").append(startTime);
        sb.append(", consumeType=").append(consumeType);
        sb.append(", orderId='").append(orderId).append('\'');
        sb.append(", channel='").append(channel).append('\'');
        sb.append(", money=").append(money);
        sb.append(", balance=").append(balance);
        sb.append('}');
        return sb.toString();
    }

    public static String parseConsumeType(Integer consumeType) {
        switch (consumeType) {
            case SETTLE_TYPE:
                return "已结算";
            case WITHDRAW_TYPE:
                return "审核中";
            case WITHDRAW_RETURN_TYPE:
                return "失败补回";
            case WITHDRAW_SUCCESS:
                return "提现成功";
            case WITHDRAW_FAIL:
                return "提现失败";
            case REBATE:
                return "返佣";
            case ADDED:
                return "补结算";
            case FIXED:
                return "补差额";
            case SERVICE_TYPE:
                return "提现手续费";
            case SERVICE_TYPE_FAIL:
                return "提现手续费失败";
            case MAKE_UP_SERVICE_TYPE:
                return "补手续费";
            case MAKE_UP_WITHHOLD:
                return "补扣款";
            default:
                return "未知状态";
        }
    }

    /**
     * 提现渠道
     *
     * @param channel 提现渠道
     * @return
     */
    public static String getChannel(Integer channel) {
        switch (channel) {
            case 1:
                return ALIPAY;
            case 2:
                return BANK;
            default:
                throw new ErrorCodeException(SupWebErrorCode.WITHOUT_WITHDRAW_TYPE.getError());
        }
    }
}
